﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/*
在以下情况下可以考虑使用外观模式：

(1)设计初期阶段，应该有意识的将不同层分离，层与层之间建立外观模式。

(2) 开发阶段，子系统越来越复杂，增加外观模式提供一个简单的调用接口。

(3) 维护一个大型遗留系统的时候，可能这个系统已经非常难以维护和扩展，但又包含非常重要的功能，为其开发一个外观类，以便新系统与其交互。
*/


public class Player
{
    static Player _player = null;
    private Player()
    {
        HP = 100;
    }
    public static Player GetInstance()
    {
        if (_player == null)
        {
            _player = new Player();
        }
        return _player;
    }
    public int HP { get; set; }
    public int Coins { get; set; }
}


public static class Adventure
{
    public static string Explore(int mapId)
    {
        Debug.Log("Explore the map " + mapId);
        Player.GetInstance().HP -= 10;
        return "stone";
    }
}

public static class PawnShop
{
    public static void Sell(string stuffName)
    {
        Debug.Log("Sell the stuff " + stuffName);
        Player.GetInstance().Coins += 10;
    }
}

public static class Hospital
{
    public static void Heal()
    {
        Player player = Player.GetInstance();
        if (player.Coins >= 20)
        {
            Debug.Log("Player is recovered");
            Player.GetInstance().Coins -= 20;
            Player.GetInstance().HP += 50;
        }
    }
}

public static class HookFascade
{
    public static void StartToHook(int mapIdStart, int mapIdEnd)
    {
        if (mapIdStart > mapIdEnd)
        {
            return;
        }
        for (int i = mapIdStart; i <= mapIdEnd; i++)
        {
            string drop = Adventure.Explore(i);
            PawnShop.Sell(drop);
            if (Player.GetInstance().HP <= 30)
            {
                Hospital.Heal();
            }
        }
    }
}



public class Fascade : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        HookFascade.StartToHook(1, 10);
    }


}
